package com.hmall.cart;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

//@Component // 关键：把这个类标记为一个Spring组件，让Spring来管理它
public class NacosConnectionTester implements CommandLineRunner { // 关键：实现CommandLineRunner接口

    @Autowired
    private Environment environment; // 注入Spring的环境变量对象

    @Override
    public void run(String... args) throws Exception {
        String testValue = environment.getProperty(""); // <-- 读取新的测试属性

        System.out.println("\n\n\n==================== 底线测试 ====================");
        System.out.println("读取到的 [perfect.test] 属性值: " + testValue);
        if (testValue != null) {
            System.out.println("结论: Nacos配置加载成功！问题出在原配置文件的语法或内容上。");
        } else {
            System.out.println("结论: Nacos配置加载失败！问题出在项目依赖或框架本身！");
        }
        System.out.println("================================================\n\n\n");
    }
}